﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;

namespace WaiGaoQiaoWeb.Controllers
{
    public class WarehouseSummaryNewController : Controller
    {
        WarehouseSummaryNewInfo info = new WarehouseSummaryNewInfo();
        public ActionResult WarehouseSummaryNewIndex()
        {
            ViewData["yy"] = GetOutstockYY();
            ViewData["mm"] = GetOutstockMM();
            ViewData["canteen"] = GetYaxNode();
            ViewData["type"] = GetType1();
            ViewData["canteen1"] = GetYaxNode1();
            ViewData["GetYaxNode"] = GetYaxNode();
            ViewData["typename"] = GetTypeName();
            return View();
        }

        /// <summary>
        /// 获取食材类型列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetTypeName()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("主食", "主食");
            dic.Add("副食", "副食");
            dic.Add("调味品", "调味品");
            IList<SelectListItem> selectList =
                 dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 获取年份列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetOutstockYY()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, (DateTime.Now.Date.Year - 1).ToString());
            dic.Add(2, (DateTime.Now.Date.Year).ToString());
            dic.Add(3, (DateTime.Now.Date.Year + 1).ToString());
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem()
                {
                    Text = m.Value.ToString(),
                    Value = m.Key.ToString(),
                    Selected = (m.Value == (DateTime.Now.Date.Year).ToString()) ? true : false
                }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取月份列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetOutstockMM()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "1");
            dic.Add(2, "2");
            dic.Add(3, "3");
            dic.Add(4, "4");
            dic.Add(5, "5");
            dic.Add(6, "6");
            dic.Add(7, "7");
            dic.Add(8, "8");
            dic.Add(9, "9");
            dic.Add(10, "10");
            dic.Add(11, "11");
            dic.Add(12, "12");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem()
                {
                    Text = m.Value.ToString(),
                    Value = m.Key.ToString(),
                    Selected = (m.Value == DateTime.Now.Month.ToString()) ? true : false
                }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取食堂列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetYaxNode()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            YaxNodeInfo yaxinfo = new YaxNodeInfo(true);
            IList<YaxNodeInfo> yaxlist = yaxinfo.SelYaxNodeInfo("and CONFLAG=1");
            foreach (YaxNodeInfo yaxnode in yaxlist)
            {
                dic.Add(yaxnode.NodeID, yaxnode.Nodename);
            }
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 获取食堂列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetYaxNode1()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            DataSet ds = info.GetGroup();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                dic.Add(Convert.ToInt32(dr["ID"]), dr["Group_Name"].ToString());
            }
            //dic.Add(1, "一食堂主副调日班");
            //dic.Add(2, "一食堂主副调夜班");
            //dic.Add(3, "二食堂主副调早饭");
            //dic.Add(4, "二食堂主副调中饭");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 获取食材类型列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetType1()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "主副");
            dic.Add(2, "调味品");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult StaffCanteenWarehouseOut3(int yy, int mm)
        {
            return EContent3(yy, mm);
        }

        public ExcelContentResult EContent3(int yy, int mm)
        {
            StringBuilder sBuilder = new StringBuilder();
            DataSet ds1 = info.GetCostAccount(yy, mm, 1);
            DataSet ds2 = info.GetCostAccount(yy, mm, 2);
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr><td colspan='7' style='font-size: 25px; text-align: center;'>员工食堂盈亏表</td></tr>");
            sBuilder.Append("<tr><td colspan='7' style='font-size: 14px; text-align: right;'>" + yy + "年" + mm + "月</td></tr>");
            sBuilder.Append("<tr><td colspan='7' style='font-size: 17px; text-align: left;'>第一食堂</td></tr>");
            sBuilder.Append("<tr><td align='center'></td><td colspan='3' align='center' style='font-size: 17px;'>日班</td><td colspan='3' align='center' style='font-size: 17px;'>夜班</td></tr>");
            sBuilder.Append("<tr> <td width='80px' align='center'></td><td width='80px' align='center' style='font-size: 17px;'>数量<br />(客)</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>单价</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>金额<br />(元)</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>数量<br />(客)</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>单价</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>金额<br />(元)</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>拉卡</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT1All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM1All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT1All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM1All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>清单</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT5All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM5All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT5All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM5All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>外卖</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT2All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM2All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT2All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM2All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>招待券</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT3All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM3All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT3All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM3All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>外理</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT4All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM4All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT4All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM4All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>收入</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT7All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM7All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT7All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM7All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>支出</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[0].Rows[0]["AMOUNT"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[0].Rows[0]["AMOUNT"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>盈亏<br />(元)</td>");
            sBuilder.Append("<td colspan='3' align='center' style='font-size: 14px;'>" + (Convert.ToDecimal(ds1.Tables[1].Rows[0]["SUM7All"]) - Convert.ToDecimal(ds1.Tables[0].Rows[0]["AMOUNT"])).ToString() + "</td>");
            sBuilder.Append("<td colspan='3' align='center' style='font-size: 14px;'>" + (Convert.ToDecimal(ds2.Tables[1].Rows[0]["SUM7All"]) - Convert.ToDecimal(ds2.Tables[0].Rows[0]["AMOUNT"])).ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            sBuilder.Append("<br /><br />");    //第二食堂
            ds1 = info.GetCostAccount(yy, mm, 10);
            ds2 = info.GetCostAccount(yy, mm, 14);
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr><td colspan='7' style='font-size: 17px; text-align: left;'>第二食堂</td></tr>");
            sBuilder.Append("<tr><td align='center'></td><td colspan='3' align='center' style='font-size: 17px;'>早饭</td><td colspan='3' align='center' style='font-size: 17px;'>中饭</td></tr>");
            sBuilder.Append("<tr> <td width='80px' align='center'></td><td width='80px' align='center' style='font-size: 17px;'>数量<br />(客)</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>单价</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>金额<br />(元)</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>数量<br />(客)</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>单价</td>");
            sBuilder.Append("<td width='80px' align='center' style='font-size: 17px;'>金额<br />(元)</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>拉卡</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT1All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM1All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT1All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM1All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>招待券</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT3All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM3All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT3All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM3All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>外卖</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT2All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM2All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT2All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM2All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>清单</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT5All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM5All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT5All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM5All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>包房</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT6All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM6All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT6All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM6All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>收入</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["COUNT7All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[1].Rows[0]["SUM7All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["COUNT7All"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[1].Rows[0]["SUM7All"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>支出</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds1.Tables[0].Rows[0]["AMOUNT"].ToString() + "</td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'></td>");
            sBuilder.Append("<td align='center' style='font-size: 14px;'>" + ds2.Tables[0].Rows[0]["AMOUNT"].ToString() + "</td></tr>");
            sBuilder.Append("<tr><td align='center' style='font-size: 17px;'>盈亏<br />(元)</td>");
            sBuilder.Append("<td colspan='3' align='center' style='font-size: 14px;'>" + (Convert.ToDecimal(ds1.Tables[1].Rows[0]["SUM7All"]) - Convert.ToDecimal(ds1.Tables[0].Rows[0]["AMOUNT"])).ToString() + "</td>");
            sBuilder.Append("<td colspan='3' align='center' style='font-size: 14px;'>" + (Convert.ToDecimal(ds2.Tables[1].Rows[0]["SUM7All"]) - Convert.ToDecimal(ds2.Tables[0].Rows[0]["AMOUNT"])).ToString() + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "YingKuiAllReport";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult StaffCanteenWarehouseOut2(string yy, string mm, string shitang, string shitangname, string leixing)
        {
            return EContent2(yy, mm, shitang, shitangname, leixing);
        }

        public ExcelContentResult EContent2(string yy, string mm, string shitang, string shitangname, string leixing)
        {
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td colspan='11' style='font-size:25px; text-align:center;font-weight:bold'>食堂进出库明细表</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td colspan='11' style='font-size:25px; text-align:left;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + yy + "年" + mm + "月" + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr>");
            sBuilder.Append("<td colspan='11' style='font-size:20px; text-align:left;font-weight:bold'>" + shitangname + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + leixing + "</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>日期</td>");
            sBuilder.Append("<td colspan='4' style='text-align:center; font-size:17px;font-weight:bold'>入库</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:17px;font-weight:bold'>出库</td>");
            sBuilder.Append("<td colspan='3' style='text-align:center; font-size:17px;font-weight:bold'>本月库存</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;'></td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>名称</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>金额</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>数量</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>单价</td>");
            sBuilder.Append("<td style='text-align:center; font-size:17px;font-weight:bold'>金额</td>");
            sBuilder.Append("</tr>");
            WarehouseSummaryNewInfo wsn = new WarehouseSummaryNewInfo();
            DataSet ds = wsn.GetInOutWarehouseDetail(yy, mm, shitang, leixing);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {

                if (ds.Tables[0].Rows[i]["RDATE"].ToString().Substring(ds.Tables[0].Rows[i]["RDATE"].ToString().Length - 2) == "合计")
                {
                    sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                    sBuilder.Append("<td rowspan='2' font-size:20px; style='text-align:center;font-weight:bold'>合计</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["GOODSNAME"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["COUNT1"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["PRICE1"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["Sum1"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["COUNT2"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["PRICE2"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["Sum2"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["COUNT3"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["PRICE3"].ToString() + "</td>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>" + ds.Tables[0].Rows[i]["Sum3"].ToString() + "</td>");
                    sBuilder.Append("</tr>");
                    sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                    sBuilder.Append("<td style='text-align:center;font-weight:bold'>上月库存</td>");
                    sBuilder.Append("<td colspan='3' style='text-align:center;font-weight:bold'>本月入库</td>");
                    sBuilder.Append("<td colspan='3' style='text-align:center;font-weight:bold'>本月出库</td>");
                    sBuilder.Append("<td colspan='3' style='text-align:center;font-weight:bold'>本月库存</td>");
                    sBuilder.Append("</tr>");
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                        sBuilder.Append("<td colspan='11'></td>");
                        sBuilder.Append("</tr>");
                        sBuilder.Append("<tr style='font-size:17px; white-space: nowrap;'>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'></td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>名称</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>数量</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>单价</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>金额</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>数量</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>单价</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>金额</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>数量</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>单价</td>");
                        sBuilder.Append("<td style='text-align:center; font-size:17px;'>金额</td>");
                        sBuilder.Append("</tr>");
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }

                sBuilder.Append("<tr style='font-size:14px; white-space: nowrap;'>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["RDATE"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["GOODSNAME"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["COUNT1"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["PRICE1"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["Sum1"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["COUNT2"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["PRICE2"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["Sum2"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["COUNT3"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["PRICE3"].ToString() + "</td>");
                sBuilder.Append("<td style='text-align:center;'>" + ds.Tables[0].Rows[i]["Sum3"].ToString() + "</td>");
                sBuilder.Append("</tr>");

            }

            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "CostAccount";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult StaffCanteenWarehouseOut1(string yy, string mm, string yax, string yaxname)
        {
            return EContent1(yy, mm, yax, yaxname);
        }

        public ExcelContentResult EContent1(string yy, string mm, string yax, string yaxname)
        {
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr><td style='font-size:25px;' align='center'>" + yaxname + "(主副调)</td></tr>");
            sBuilder.Append("<tr><td>");
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1' style='border:border-width;'>");
            sBuilder.Append("<tr style='font-size: 17px;width: 840px'>");
            sBuilder.Append("<td align='center' width='120px'>日期</td>");
            sBuilder.Append("<td align='center' width='120px'>主</td>");
            sBuilder.Append("<td align='center' width='120px'>副</td>");
            sBuilder.Append("<td align='center' width='120px'>调</td>");
            sBuilder.Append("<td align='center' width='120px'>合计</td>");
            sBuilder.Append("<td align='center' width='120px'>收入</td>");
            sBuilder.Append("<td align='center' width='120px'>盈亏</td>");
            sBuilder.Append("</tr>");
            DataSet ds = info.GetList(yy, mm, yax);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                sBuilder.Append("<tr style='font-size: 14px;width: 840px'>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["日期"].ToString() + "</td>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["主"].ToString() + "</td>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["副"].ToString() + "</td>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["调"].ToString() + "</td>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["合计"].ToString() + "</td>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["收入"].ToString() + "</td>");
                sBuilder.Append("<td align='center' width='120px'>" + ds.Tables[0].Rows[i]["盈亏"].ToString() + "</td>");
                sBuilder.Append("</tr>");
                if (i == ds.Tables[0].Rows.Count - 2)
                {
                    sBuilder.Append("<tr style='font-size: 14px;width: 840px'>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("<td></td>");
                    sBuilder.Append("</tr>");
                }
            }
            sBuilder.Append("</table>");
            sBuilder.Append("</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "StaffCanteenWarehouseOut1";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult StaffCanteenWarehouseOut(string yy, string mm, string yax, string yaxname)
        {
            return EContent(yy, mm, yax, yaxname);
        }

        public ExcelContentResult EContent(string yy, string mm, string yax, string yaxname)
        {
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr><td style='font-size:25px;' colspan='11'>员工食堂仓库汇总表</td></tr>");
            sBuilder.Append("<tr><td colspan='11'>");
            sBuilder.Append(yaxname + "（主食、副食、调味品）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                        "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                        "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                        "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + yy + "年" + mm + "月");
            sBuilder.Append("</td></tr>");
            sBuilder.Append("<tr><td colspan='11'>");
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1' style='border:border-width;'>");
            sBuilder.Append("<tr style='font-size: 17px;'>");
            sBuilder.Append("<td align='center'>品名</td>");
            sBuilder.Append("<td align='center'>单位</td>");
            sBuilder.Append("<td align='center'>单价</td>");
            sBuilder.Append("<td colspan='2' align='center'>上月结存</td>");
            sBuilder.Append("<td colspan='2' align='center'>本月收入</td>");
            sBuilder.Append("<td colspan='2' align='center'>本月发出</td>");
            sBuilder.Append("<td colspan='2' align='center'>本月结存</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size: 17px;'>");
            sBuilder.Append("<td></td>");
            sBuilder.Append("<td></td>");
            sBuilder.Append("<td></td>");
            sBuilder.Append("<td align='center'>数量</td>");
            sBuilder.Append("<td align='center'>金额</td>");
            sBuilder.Append("<td align='center'>数量</td>");
            sBuilder.Append("<td align='center'>金额</td>");
            sBuilder.Append("<td align='center'>数量</td>");
            sBuilder.Append("<td align='center'>金额</td>");
            sBuilder.Append("<td align='center'>数量</td>");
            sBuilder.Append("<td align='center'>金额</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</td>");
            DataSet ds = info.GetListWarehouseSummary(yy, mm, yax);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {

                if (ds.Tables[0].Rows[i]["GOODSNAME"].ToString() == "小计")
                {
                    sBuilder.Append("<tr style='font-size: 14px;'>");
                    sBuilder.Append("<td colspan='3' style='font-weight: bold'>合计</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT1"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum1"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT2"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum2"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT3"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum3"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT4"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum4"] + "</td>");
                    sBuilder.Append("</tr>");
                    sBuilder.Append("<tr>");
                    sBuilder.Append("<td style='height: 20px' colspan='11'></td>");
                    sBuilder.Append("</tr>");
                    i += 2;
                }
                if (ds.Tables[0].Rows[i]["GOODSNAME"].ToString() == "合计")
                {
                    sBuilder.Append("<tr style='font-size: 14px;'>");
                    sBuilder.Append("<td colspan='3' style='font-weight: bold'>主副调总合计</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT1"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum1"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT2"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum2"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT3"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum3"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT4"] + "</td>");
                    sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum4"] + "</td>");
                    sBuilder.Append("</tr>");
                    sBuilder.Append("<tr style='font-size: 14px;'>");
                    sBuilder.Append("<td colspan='11'>制表:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                    "主管:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                    "会计:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;复核:</td>");
                    sBuilder.Append("</tr>");
                    sBuilder.Append("</table>");
                    break;
                }
                if (ds.Tables[0].Rows[i]["GOODSNAME"].ToString() == "主食" || ds.Tables[0].Rows[i]["GOODSNAME"].ToString() == "副食" || ds.Tables[0].Rows[i]["GOODSNAME"].ToString() == "调味品")
                {
                    i++;
                }
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["GOODSNAME"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["UNIT"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["PRICE"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT1"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum1"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT2"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum2"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT3"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum3"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["COUNT4"] + "</td>");
                sBuilder.Append("<td align='center'>" + ds.Tables[0].Rows[i]["Sum4"] + "</td>");
                sBuilder.Append("</tr>");
            }

            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "StaffCanteenWarehouseOut";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }
    }
}
